<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#eee"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">{{ title }}游记</view>
      <view class="head_right">
        <view class="show" @click="creates(id)">
          <image
            src="@/static/images/slices/icon_wddc_tianjia.png"
            mode=""
          ></image>
        </view>
      </view>
    </view>

    <scroll-view
      :style="{
        height: scrollHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
      @scrolltolower="scrolltolower"
    >
      <view class="box">
        <log-list
          bgColor="rgba(39,39,39,0.5)"
          color="#adadad"
          color1="#eee"
          :type="type"
          :list="detail.data"
        ></log-list>
        <view class="empty" v-if="!showNone">
          <image src="@/static/images/pic_yl_kong.png" mode=""></image>
          <view class="empty_text"> 暂无游历数据 </view>
          <view class="empty_btn" @click="toShanhai"> 前往山海 </view>
        </view>
      </view>
    </scroll-view>

    <floatingBall></floatingBall>
  </view>
</template>

<script>
import logList from "@/components/logList.vue"; //游记
export default {
  components: {
    logList,
  },
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      scrollHeihgt: 0,
      id: "",
      detail: {},
      showNone: false,
      title: "",
      page: 1,
      list_page: 0,
    };
  },
  onLoad(options) {
    this.id = options.id;
    this.title = options.name;
    this.type = options.type;
  },
  onShow: function () {
    this.page = 1;
    this.list_page = 0;
    this.getDetail(this.id);
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum;
      });
    });
  },
  methods: {
    creates(guanlianid) {
      uni.navigateTo({
        url: `/pages/bigResult/minute_create?guanlianid=${guanlianid}&type=6`,
      });
    },
    scroll() {},
    toShanhai() {
      uni.navigateTo({
        url: "/pages/index/index",
      });
    },
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    getDetail(id) {
      this.$http
        .usergongnengYouLiDetail({ id: id,page:this.page })
        .then((res) => {
          console.log(res.data.list, "游历详情");
          // this.detail = res.data.list;
          if (res.data.list.current_page == 1) {
            this.detail = res.data.list;
          } else {
            this.detail.data = this.detail.data.concat(res.data.list.data);
          }
          this.last_page = res.data.list.last_page;
          if (this.detail.data.length > 0) {
            this.showNone = true;
          } else {
            this.showNone = false;
          }
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++;
        this.getDetail(this.id);
      }
      console.log("触发");
    },
  },
};
</script>

<style scoped lang="scss">
.content {
  box-sizing: border-box;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
  position: fixed;
  left: 0;
  top: 0;
}

.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
    display: flex;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eee;
  }
}

.show {
  width: 40rpx;
  height: 38rpx;

  image {
    width: 100%;
    height: 100%;
  }
}

.zhuan {
  width: 40rpx;
  height: 38rpx;
  margin-left: 40rpx;

  image {
    width: 100%;
    height: 100%;
  }
}

.box {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;
}
.empty {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 240rpx;
  image {
    width: 410rpx;
    height: 342rpx;
  }
  .empty_text {
    font-size: 30rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    color: #adadad;
    margin-top: 24rpx;
  }
  .empty_btn {
    width: 530rpx;
    height: 96rpx;
    background: linear-gradient(360deg, #50b674 0%, #aeddbd 100%);
    border-radius: 48rpx 48rpx 48rpx 48rpx;
    margin-top: 72rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 30rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}
</style>